<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        // 输入 { name: 'zhangsan', age: 18, sex: 'male', weight: 100 }

        // 返回 [
        // ​     { a: 'name', b: 'zhangsan' },
        // ​     { a: 'age', b: 18 },
        // ​     { a: 'sex', b: 'male' },
        // ​     { a: 'weight', b: 100 },
        //  ]

        function obj2arr (obj) {
            const result = [];
            for (const key in obj) {
                const value = obj[key];
                result.push({
                    a: key,
                    b: value,
                });
            }
            return result;
        }

        console.log( obj2arr({ name: 'zhangsan', age: 18, sex: 'male', weight: 100 }) );

    </script>
</body>
</html>